package com.example.demo.lab2.controller;

import com.example.demo.lab2.entity.Departments;
import com.example.demo.lab2.entity.EmpWithDep;
import com.example.demo.lab2.entity.Employees;
import com.example.demo.lab2.service.EmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;


@Controller
@RequestMapping("v1")
public class EmployeesController {

    @Autowired
    private EmployeesService employeesService;

    @GetMapping("/emp/list")
    public ResponseEntity<?> list() {
        List<Employees> employeesList = employeesService.list();
        return ResponseEntity.ok(employeesList);
    }

    @PostMapping("/emp/insert")
    public ResponseEntity<?> insert(@RequestBody Employees employees) {
        int insert = employeesService.insert(employees);
        return ResponseEntity.ok(insert);
    }
    @PostMapping("/emp/update")
    public ResponseEntity<?> update(@RequestBody Employees employees){
        int update = employeesService.update(employees);
        return ResponseEntity.ok(update);
    }
    @PostMapping("/emp/delete")
    public ResponseEntity<?> delete(@RequestParam("id") BigDecimal id ){
        int delete = employeesService.delete(id);
        return ResponseEntity.ok(id);
    }
    //连表查

    @PostMapping("/emp/listWithDep")
    public ResponseEntity<?> listWithDep(){
        List<EmpWithDep> empWithDeps = employeesService.listWithDep();
        return ResponseEntity.ok(empWithDeps);
    }
}
